package com.runner.player.state;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.runner.entity.CollisionEntity;
import com.runner.observer.Event;
import com.runner.player.Player;

public class AirDiveState extends PlayerState {

	private float timer;
	public static float DIVE_TIME = 0.4f;
	private Vector2 posVec;
	private float angle;
	private float startAngle;
	private float endAngle;

	public AirDiveState(Player p) {
		super(p);
	}

	@Override
	public void update(float delta) {
		//lerp angle
		angle=startAngle-(timer/0.4f*(startAngle-endAngle));
		player.getPhysics().getBody().setTransform(posVec, angle);
		player.setDirection(angle*MathUtils.radiansToDegrees);
		timer += delta;
		if (timer > DIVE_TIME) {
			exit();
			player.changeState(new FallingState(player));
		}
		player.getPhysics().getBody().setLinearVelocity(0,0);
	}

	@Override
	public void newAction(INPUT input) {
		switch (input) {
		default:
			break;
		}
	}

	@Override
	public void enter() {
		startAngle=-1.07f;
		endAngle=-1.77f ;
		posVec = new Vector2(player.getPhysics().getBody().getPosition().x, player.getPhysics().getBody().getPosition().y);
		player.getPhysics().getBody().setTransform(posVec, startAngle);
		player.getSubject().notify(Event.EVENT_DIVE);
		player.setDirection(90);
		timer = 0;
	}

	@Override
	public void exit() {
		//player.setDirection(0);
	}

	@Override
	public void collide(CollisionEntity otherBody) {

	}

}
